package com.aiapphub.SystemCode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aiapphub.BaseCode.utils.BeanCopyUtils;
import com.aiapphub.BaseCode.vo.PageVo;
import com.aiapphub.SystemCode.entity.FileInfo;
import com.aiapphub.SystemCode.mapper.FileInfoMapper;
import com.aiapphub.SystemCode.service.FileInfoService;
import com.aiapphub.SystemCode.vo.FileInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 上传日志表(FileInfo)表服务实现类
 *
 * @author makejava
 * @since 2023-07-18 08:46:32
 */
@Service("uploadFileService")
public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> implements FileInfoService {


    @Autowired(required = false)
    private FileInfoMapper fileInfoMapper;

    /**
     * 分页查询上传文件数据
     *
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return 包含查询结果和总记录数的分页对象
     */
    @Override
    public PageVo selectUploadFilePage(Integer pageNum, Integer pageSize) {
        // 构造查询条件
        LambdaQueryWrapper<FileInfo> queryWrapper = new LambdaQueryWrapper<>();
        // 查询状态为 0 的数据
        //queryWrapper.eq(FileInfo::getStatus, SystemConstants.ARTICLE_STATUS_NORMAL);
        // 分页查询数据
        Page<FileInfo> page = new Page<>(pageNum, pageSize);
        page(page, queryWrapper);

        // 将查询结果列表转换成分页对象，并返回给客户端
        List<FileInfoVo> fileInfoVos = BeanCopyUtils.copyBeanList(page.getRecords(), FileInfoVo.class);
        PageVo pageVo = new PageVo(fileInfoVos, page.getTotal());
        return pageVo;
    }

    /***
     * 批量导出所选择数据
     * @param ids
     * @return
     */
    @Override
    public List<FileInfo> getByIds(List<Long> ids) {
        LambdaQueryWrapper<FileInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(FileInfo::getId, ids);
        return fileInfoMapper.selectList(queryWrapper);
    }

    @Override
    public PageVo selectCategoryPage(FileInfo fileInfo, Integer pageNum, Integer pageSize) {
        // 构造查询条件
        LambdaQueryWrapper<FileInfo> queryWrapper = new LambdaQueryWrapper<>();

        // 模糊查询文件名称
        queryWrapper.like(StringUtils.hasText(fileInfo.getFilename()), FileInfo::getFilename, fileInfo.getFilename());

        // 模糊查询文件路径
        queryWrapper.like(StringUtils.hasText(fileInfo.getFilepath()), FileInfo::getFilepath, fileInfo.getFilepath());

        // 查询文件状态
        queryWrapper.eq(fileInfo.getStatus() != null, FileInfo::getStatus, fileInfo.getStatus());

        // 分页查询数据
        Page<FileInfo> page = new Page<>(pageNum, pageSize);
        page(page, queryWrapper);

        // 将查询结果列表转换成分页对象，并返回给客户端
        List<FileInfoVo> fileInfoVos = BeanCopyUtils.copyBeanList(page.getRecords(), FileInfoVo.class);
        PageVo pageVo = new PageVo(fileInfoVos, page.getTotal());
        return pageVo;
    }



}

